package 数组.easy;

/**
 * @author Lw中
 * @date 2020/8/4 8:56
 */
public class YiErJiuJiu {

    public static int[] replaceElements(int[] arr) {
        int[] result = new int[arr.length];
        int max = -1;
        for (int i = arr.length-1; i>=0 ; i--) {
            result[i] = max;
            max = arr[i] > max ? arr[i] : max;
        }
        return result;
    }

    public static void main(String[] args) {
        int[] arr = {17, 18, 5, 4, 1};
        int[] result = replaceElements(arr);
        for (int i = 0; i < result.length; i++) {
            System.out.println(result[i]);
        }
    }

}
